import React, { Component } from 'react'
import { List } from 'antd-mobile';
import axios from 'axios'
import '../../assets/css/home/k-news.less'
import { hashHistory } from 'react-router'
const Item = List.Item;
const Brief = Item.Brief;


export default class KNews extends Component {
    state = {
        data: []
    }
    gotoDetial(id) {
        hashHistory.push({
            pathname: `/detail/${id}`
        })
    }
    render() {
        return (
            <div className="k-news">
                <h4>相关资讯</h4>
                <List>
                    {
                        this.state.data.map(e => {
                            return <Item
                                key={e.id}
                                arrow="horizontal"
                                thumb={e.avatar}
                                multipleLine
                                onClick={this.gotoDetial.bind(this, e.id)}
                            >
                                {e.title} <Brief>{e.subtitle}</Brief>
                            </Item>
                        })
                    }
                </List>
            </div>
        )
    }
    async componentDidMount() {
        const { data } = await axios.get('/data/news.json')
        // console.log(result);
        this.setState({ data })
    }
}
